<template>
  <div>
    <a-card :bordered="false" style="width: 900px;" class="process_index">
      <a-table
        rowKey="id"
        size="middle"
        @change="handleTableChange"
        @refresh="getList"
        :columns="columns"
        :data-source="commentList"
        :loading="loading"
        :pagination="false"
      >
      </a-table>
    </a-card>
  </div>
</template>
<script>
import { listBizOrderProduct, delBizOrderProduct, exportBizOrderProduct } from '@/api/biz/bizOrderProduct'

import { listBizOrderProcessRecord,updateBizOrderProcessRecord } from '@/api/biz/bizOrderProcessRecord'
import AdvanceTable from '@/components/pt/table/AdvanceTable'
export default {
  name: 'BizOrderComment',
    props: {
      orderId: {
        type: String,
        required: true
      },
      title: {
        type: String,
        default: '子表'
      },
      selectedInfo:{
        type: Object,
        required: false
      },
    },
  components: {
    AdvanceTable,

  },
  data () {
    return {
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 销售单产品表格数据
      commentList: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 1000
      },
      columns: [
        // {
        //   title: '工序操作',
        //   dataIndex: 'productId',
        //   ellipsis: true,
        //   align: 'center',
        //   width: '12.8%'
        // },
        {
          title: '工序名称',
          ellipsis: true,
          align: 'center',
          width: '8%',
          dataIndex:'processName',
        },
        {
          title: '操作员',
          ellipsis: true,
          align: 'center',
          width: '12.8%',
          dataIndex:'createByName',
        },
        {
          title: '计划量',
          ellipsis: true,
          align: 'center',
          width: '8%',
          dataIndex:'processVol',
        },
        {
          title: '单位',
          ellipsis: true,
          align: 'center',
          width: '6%',
          dataIndex:'unitName',
        },
        {
          title: '完工情况',
          ellipsis: true,
          align: 'center',
          width: '8%',
          dataIndex:'completedVol',
          customRender:(text,record)=>{
            if(text == 1){
              return '是'
            }else{
              return '否'
            }
          }
        },
        {
          title: '备注',
          ellipsis: true,
          align: 'center',
          dataIndex:'remark',
        },
        {
          title: '操作时间',
          ellipsis: true,
          align: 'center',
          width: '18%',
          dataIndex:'updateTime',
        }
      ]
    }
  },
  created () {
    this.getList()
  },
  watch: {
    selectedInfo(newValue, oldValue) {
      if(!newValue.productId || !newValue.orderProductId) return;
      let param = {
        orderId:this.orderId,
        productId:newValue.productId,
        orderProductId:newValue.orderProductId
      }
      this.loading = true
      listBizOrderProcessRecord(param).then(res=>{
        this.loading = false
        if(res.code == 200) {
          this.commentList = res.data.list
          this.$emit('processOk',newValue)
        }else{
          this.message.error(res.msg)
        }
      }).catch(()=>{
        this.loading = false
      })
    }
  },
  methods: {
    /** 查询销售单产品列表 */
    getList () {
      
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParam.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.queryParam = {
        pageNum: 1,
        pageSize: 1000,
        productId: undefined,

        orderId: undefined,

        number: undefined,

        price: undefined

      }
      this.handleQuery()
    },
    /** 翻页操作 */
    onShowSizeChange (current, pageSize) {
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    /** 翻页操作 */
    onSizeChange (current, size) {
      this.queryParam.pageNum = 1
      this.queryParam.pageSize = size
      this.getList()
    },
    /** 翻页操作 */
    changeSize (current, pageSize) {
      this.queryParam.pageNum = current
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    /** 翻页操作 */
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      this.ids = this.selectedRows.map(item => item.id)
      this.single = selectedRowKeys.length !== 1
      this.multiple = !selectedRowKeys.length
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    handleAdd () {
      this.showAddModal = true
      this.$nextTick(() => (
        this.$refs.bizOrderProductAddForm.handleAdd()
      ))
    },
    handleUpdate (record, ids) {
      this.showEditModal = true
      this.$nextTick(() => (
        this.$refs.bizOrderProductEditForm.handleUpdate(record, ids)
      ))
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      var that = this
      const bizOrderProductIds = row.id || this.ids
      this.$confirm({
        title: '确认删除所选中数据?',
        onOk () {
          return delBizOrderProduct(bizOrderProductIds)
            .then(() => {
              that.onSelectChange([], [])
              that.getList()
              that.$message.success(
                '删除成功',
                3
              )
          })
        },
        onCancel () {}
      })
    },
    /** 导出按钮操作 */
    handleExport () {
      var that = this
      this.$confirm({
        title: '是否确认导出?',
        content: '此操作将导出当前条件下所有数据而非选中数据',
        onOk () {
          return exportBizOrderProduct(that.queryParam)
            .then(response => {
              that.download(response.msg)
              that.$message.success(
                '导出成功',
                3
              )
          })
        },
        onCancel () {}
      })
    },
    handleTableChange (pagination, filters, sorter) {
      if (sorter.field !== undefined && sorter.field !== null && sorter.field !== '') {
        this.queryParam.orderByColumn = 'a.' + sorter.field
        this.queryParam.isAsc = sorter.order
      }
      this.getList()
    }
  }
}
</script>

<style type="text/css">
  
  .process_index .ant-table-body{
    height: auto !important;
    overflow: auto !important;
  }
</style>